package com.hymjweb.demo.hymj.native_bill_manage.other_charges.mapper;

import com.hymjweb.demo.hymj.native_bill_manage.other_charges.bean.BNativeBillOtherCharges;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface BNativeBillOtherChargesMapper {

    class BNativeBillOtherChargesMapperProvider{

        public String getListByBillId(String billId) {
            String sql= new SQL() {{
                SELECT("t.* ");
                FROM("b_native_bill_other_charges t ");
                WHERE("1=1 and t.native_bill_id = #{billId}");
            }}.toString();

            return sql;
        }


        public String deleteByBillId(String billId) {
            String sql = new SQL() {{
                DELETE_FROM("b_native_bill_other_charges t");
                WHERE("t.native_bill_id = #{billId}");
            }}.toString();
            return sql;
        }

        public String deleteById(String id){
            String sql = new SQL() {{
                DELETE_FROM("b_native_bill_other_charges t");
                WHERE("t.id = #{id}" );
            }}.toString();
            return sql;
        }

    }

    /**
     *
     * @param billId
     * @return
     */

    @Results(id = "bNativeBillOtherChargesMapId",value = {
            @Result(column = "id", property = "id"),
            @Result(column = "native_bill_id", property = "nativeBillId"),
            @Result(column = "name", property = "name"),
            @Result(column = "amount", property = "amount"),
            @Result(column = "comment", property = "comment")
    })
    @SelectProvider(type = BNativeBillOtherChargesMapperProvider.class, method = "getListByBillId")
    List<BNativeBillOtherCharges> getListByBillId(String billId);


    /**
     * 分单其他费用明细批量插入
     * @param otherCharges
     * @return
     */
    @Insert(
            "<script>" +
                    "insert into b_native_bill_other_charges(id,native_bill_id,name,amount,comment) values " +
                    "<foreach collection='otherCharges' item='pojo' separator=','>" +
                    "(#{pojo.id},#{pojo.nativeBillId},#{pojo.name},#{pojo.amount},#{pojo.comment})" +
                    "</foreach>" +
            "</script>"
    )
    @Options(keyProperty = "id")
    int batchInsert(@Param("otherCharges") List<BNativeBillOtherCharges> otherCharges);


    @DeleteProvider(type = BNativeBillOtherChargesMapperProvider.class, method = "deleteByBillId")
    int deleteByBillId(String billId);

    @DeleteProvider(type = BNativeBillOtherChargesMapperProvider.class, method = "deleteById")
    int deleteById(String id);
}
